package service

import (
	"fitness/go-admin/internal/model"
	"fitness/go-admin/internal/repository"
)

type DictService struct {
	dictRepo *repository.DictRepository
}

func NewDictService(dictRepo *repository.DictRepository) *DictService {
	return &DictService{dictRepo: dictRepo}
}

// DictType 相关方法

// CreateDictType 创建字典类型
func (s *DictService) CreateDictType(dictType *model.DictType) error {
	return s.dictRepo.CreateDictType(dictType)
}

// GetDictTypeByID 根据ID获取字典类型
func (s *DictService) GetDictTypeByID(id uint) (*model.DictType, error) {
	return s.dictRepo.GetDictTypeByID(id)
}

// GetDictTypeByType 根据类型获取字典类型
func (s *DictService) GetDictTypeByType(dictType string) (*model.DictType, error) {
	return s.dictRepo.GetDictTypeByType(dictType)
}

// ListDictTypes 获取字典类型列表
func (s *DictService) ListDictTypes(name, dictType string, status int, page, pageSize int) ([]*model.DictType, int64, error) {
	offset := (page - 1) * pageSize
	return s.dictRepo.ListDictTypes(name, dictType, status, offset, pageSize)
}

// UpdateDictType 更新字典类型
func (s *DictService) UpdateDictType(dictType *model.DictType) error {
	return s.dictRepo.UpdateDictType(dictType)
}

// DeleteDictType 删除字典类型
func (s *DictService) DeleteDictType(id uint) error {
	return s.dictRepo.DeleteDictType(id)
}

// DictData 相关方法

// CreateDictData 创建字典数据
func (s *DictService) CreateDictData(dictData *model.DictData) error {
	return s.dictRepo.CreateDictData(dictData)
}

// GetDictDataByID 根据ID获取字典数据
func (s *DictService) GetDictDataByID(id uint) (*model.DictData, error) {
	return s.dictRepo.GetDictDataByID(id)
}

// ListDictData 获取字典数据列表
func (s *DictService) ListDictData(dictTypeID uint, label, value string, status int, page, pageSize int) ([]*model.DictData, int64, error) {
	offset := (page - 1) * pageSize
	return s.dictRepo.ListDictData(dictTypeID, label, value, status, offset, pageSize)
}

// GetDataByDictType 根据字典类型获取字典数据
func (s *DictService) GetDataByDictType(dictType string) ([]*model.DictData, error) {
	return s.dictRepo.GetDataByDictType(dictType)
}

// UpdateDictData 更新字典数据
func (s *DictService) UpdateDictData(dictData *model.DictData) error {
	return s.dictRepo.UpdateDictData(dictData)
}

// DeleteDictData 删除字典数据
func (s *DictService) DeleteDictData(id uint) error {
	return s.dictRepo.DeleteDictData(id)
}

// BatchDeleteDictData 批量删除字典数据
func (s *DictService) BatchDeleteDictData(ids []uint) error {
	return s.dictRepo.BatchDeleteDictData(ids)
}
